﻿FlyTalk.views.QuestionForm = Ext.extend(Ext.form.FormPanel, {

	scroll: true,
    initComponent: function () {
		
		// back button on toolbar
		this.backButton = new Ext.Button({
			text: 'Back',
			ui: 'back',
			handler: this.backButtonTap,
			scope: this
		});
		
		// save button on toolbar
		this.saveButton = new Ext.Button({
			text: 'Send',
			ui: 'action',
			handler: this.saveButtonTap,
			scope: this
		});
		
		// top tool bar
		this.toolbar = new Ext.Toolbar({
			title: 'Ask',
			
			items:[
				this.backButton,
				{ xtype: 'spacer' },
				this.saveButton,	
			]
		});
	
        this.dockedItems = [this.toolbar];
	
        FlyTalk.views.QuestionForm.superclass.initComponent.call(this);
		
    },	

    backButtonTap: function () {
		this.reset();

		var next = FlyTalk.views.TalkView.tweetToolbar.title; // see which page talk is on right now
		Ext.dispatch({
            controller: FlyTalk.controllers.ftController,
            action: 'openNext',
            next: next,
        });
		/*
		if(next == 'Search'){
			var next = FlyTalk.views.TalkView.tweetToolbar.title; // see which page talk is on right now
	        Ext.dispatch({
	        	controller: FlyTalk.controllers.ftController,
	        	action: 'openSearch',
	        });
		}else{
			Ext.dispatch({
	            controller: FlyTalk.controllers.ftController,
	            action: 'openNext',
	            next: next,
	        });
		}*/
    },
    
	saveButtonTap: function () {
		 var comment = Ext.getCmp('comment').getValue();
		 var user = Ext.getCmp('selectUser').getValue();	
		 this.reset();
		 if(this.toolbar.title == 'Reply'){
			// var tid = FlyTalk.views.ColumnView.MixedStore.getAt(this.items.getAt(1).label).data;
			 var ind = this.items.getAt(1).label;
			 Ext.dispatch({
		            controller: FlyTalk.controllers.dbController,
		            action: 'saveReply',
		            text: comment,
		            index: ind,
		            uid: user,
		     });
		 }else {
			 if(this.toolbar.title == 'Ask'){
				 Ext.dispatch({
			            controller: FlyTalk.controllers.dbController,
			            action: 'saveQuestion',
			            text: comment, 
			            uid: user,
			     });
			 }else{
				 Ext.dispatch({
			            controller: FlyTalk.controllers.dbController,
			            action: 'saveComment',
			            text: comment,    
			            uid: user,
			     });
			 }
		 }
    },
    
	items: [
	{ // select a user (researcher mode only!) - THIS FIELD HAS TO BE THE FIRST. DO NOT CHANGE!
	    xtype: 'selectfield',
	    name: 'user',
	    id: 'selectUser',
	    label: 'select user',
	    labelWidth: 300,
	    labelAlign: 'top',
	    options: [
	    	{text: 'HappyTraveler',  value: '3'},
	        {text: 'Jessica', value: '4'},
	    	{text: 'TAP Airline',  value: '1'},
	    	{text: 'Airport',  value: '2'},
	    ]
	},{html: ''},	       
	{  // textarea for msg
		xtype: 'textareafield',
		id:'comment',
        name: 'title',
        label: 'Type your question here: ',
		labelWidth: 300,
		labelAlign: 'top',
		height: 140,
        required: true			
    },{
    	//add hidden button to pass values
    	xtype: 'textareafield',
        label: 'T',
        required: false,
        hidden: true,
    },
	{html: 'Attach a location:'},
	{
		xtype:'button',
		text: 'Current location',
		style: 'margin: .5em'


	},{
		xtype:'button',
		text: 'Find on map',
		style: 'margin: .5em'

	},
	{html: 'Add a photo:'},
	{
		xtype:'button',
		text: 'Camera',
		style: 'margin: .5em'
	
	},{
		xtype:'button',
		text: 'Upload',
		style: 'margin: .5em'
	
	},
//	{	//add location button
//		xtype:'button',
//		iconCls: 'locate',
//		iconMask: true,
//		width: 55,
//	   // handler: this.onCompose,		
//	},
	/*
	{	//post button
		xtype:'button',
		text: 'Post'
		
	}*/
	]	
	/* { // select a tag
        xtype: 'selectfield',
        name: 'tag',
		id: 'limit',
        label: 'Add Tag',
		labelWidth: 100,
		options: [
       		{text: 'my flight',  value: 'first'},
       		{text: 'my airline', value: 'second'},
       		{text: 'my terminal',  value: 'third'},
			{text: 'all airport',  value: 'fourth'}
    	]
	}*/
	
         
});

